



//
//  CPJTitleImageButton.swift
//  Sina
//
//  Created by YYY on 2017/8/10.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

import UIKit

class CPJTitleImageButton: UIButton {
    
    private lazy var leftTitle: UILabel = { () -> UILabel in
        let titleLabel = UILabel()
        //titleLabel.isUserInteractionEnabled = true
        titleLabel.font = UIFont.boldSystemFont(ofSize: 17)
        titleLabel.textColor = UIColor.darkGray
        return titleLabel
        }()
    
    lazy var rightImage: UIImageView = { () -> UIImageView in
        let imageView = UIImageView(image: UIImage(named: "navigationbar_arrow_down"))
      //  imageView.isUserInteractionEnabled = true
        return imageView
        }()
    
    //重载构造函数
    init(title: String?)
    {
        super.init(frame: CGRect(x: 0, y: 0, width: 0, height: 44))

        if title == nil
        {
            leftTitle.text = "首页"
        }
        else
        {
            leftTitle.text = title
        }
       
        
        let width = leftTitle.getLabelWidth(text: leftTitle.text!, font: UIFont.boldSystemFont(ofSize: 17), height: self.height)
        leftTitle.frame = CGRect(x: 0, y: 0, width: width, height: self.height)
        self.addSubview(leftTitle)
        
        
        rightImage.frame = CGRect(x: leftTitle.right+3, y: (self.height-14*0.65)/2.0, width: 26*0.65, height: 14*0.65)
        self.addSubview(rightImage)
        leftTitle.width(newWidth: leftTitle.width + rightImage.width + 5)
    }
    
   
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
 
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
